<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new sodium keypair</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.sodium-crypto-kx-keypair" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_crypto_kx_keypair</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0)</p><p class="refpurpose"><span class="refname">sodium_crypto_kx_keypair</span> &mdash; <span class="dc-title">Creates a new sodium keypair</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-crypto-kx-keypair-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_crypto_kx_keypair</strong></span>
    ( <span class="methodparam">void</span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Create a new sodium keypair consisting of the the secret key (32 bytes)
   followed by the public key (32 bytes). The keys can be retrieved by calling
   <span class="function"><a href="sodium_crypto_kx_secretkey.html" class="function">sodium_crypto_kx_secretkey()</a></span> and
   <span class="function"><a href="sodium_crypto_kx_publickey.html" class="function">sodium_crypto_kx_publickey()</a></span>, respectively.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-crypto-kx-keypair-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-crypto-kx-keypair-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the new keypair on success; throws an exception otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sodium-crypto-kx-keypair-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="openssl_spki_export.example.keygen">
   <p><strong>Example #1 <span class="function"><strong>sodium_crypto_kx_keypair()</strong></span> usage</strong></p>
   <div class="example-contents"><p>
     Create a new keypair and retrieve the secret and the public key from it.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$keypair&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_kx_keypair</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$secret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_kx_secretkey</span><span style="color: #007700">(</span><span style="color: #0000BB">$keypair</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$public&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sodium_crypto_kx_publickey</span><span style="color: #007700">(</span><span style="color: #0000BB">$keypair</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"secret:&nbsp;%s\npublic:&nbsp;%s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$secret</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$public</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
secret: e7c5c918fdc40762e6000542c0118f4368ce8fd242b0e48c1e17202797a25daf
public: d1f59fda8652caf40ed1a01d2b6f3802b60846986372cd8fa337b7c12c428b18
</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>